package com.douqu.game.core.config;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

import java.util.Arrays;

/**
 * @author wangzhenfei
 *         2017-10-11 14:07
 *         奖励配置
 */
public class ExchangeRewardConfig extends GameObject {
    /**交互类型**/
    public int type;

    /** 消耗资源 */
    public CommonData[] needAssets;

    /** 最小排名 **/
    public int minRank;
    /** 奖励组 */
    public GoodsData[] reward;

    @Override
    public boolean check()
    {
        if(needAssets == null)
        {
            LogUtils.error("ArenaReward check needAssets is null -> id:" + id + " name:" + name);
            return false;
        }

        if(reward == null)
        {
            LogUtils.error("ArenaReward check props is null -> id:" + id + " name:" + name);
            return false;
        }
        return true;
    }



    @Override
    public boolean setVariable(String key, String value)
    {
        if("reward".equals(key))
        {
            reward = LoadUtils.loadGoodDataToArray(key, value);
            return LoadUtils.checkGoods(reward, this.getClass(), key, id);
        }
        else if("needAssets".equals(key))
       {
           needAssets = LoadUtils.loadCommonDataToArray(key, value);
           return LoadUtils.checkCommonData(needAssets, this.getClass(), key, DataFactory.ASSET_KEY, id);
       }

        else
            return super.setVariable(key, value);
    }

    @Override
    public String toString() {
        return "ArenaReward{" +
                "minRank=" + minRank +
                ", needAssets=" + Arrays.toString(needAssets) +
                '}';
    }
}
